package mortal.game.control
{
    import Message.Game.*;
    import Message.Public.*;
    import flash.events.*;
    import modules.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.view.player.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class PlayerInfoController extends Controller
    {
        private var _playerModule:PlayerModule;
        private var _isLookUp:Boolean = false;

        public function PlayerInfoController()
        {
            NetDispatcher.addCmdListener(ServerCommand.PlayerInfoReply, this.onPlayerInfoMsg);
            Dispatcher.addEventListener(EventName.PlayerInfo_view, this.viewHandler);
            
        }

        override protected function initView() : IView
        {
            if (this._playerModule == null)
            {
                this._playerModule = new PlayerModule();
                this._playerModule.x = 300;
                this._playerModule.y = 100;
                this._playerModule.mode = PlayerModule.Mode_Other;
            }
            this._playerModule.addEventListener(Event.ADDED_TO_STAGE, this.initOnAddToAtage);
            return this._playerModule;
        }

        private function initOnAddToAtage(event:Event) : void
        {
            
        }

        public function viewPlayerInfo(param1:int) : void
        {
            
        }

        private function onPlayerInfoMsg(param1:Object = null) : void
        {
            var _loc_3:int = 0;
            var _loc_4:Array = null;
            var _loc_5:int = 0;
            var _loc_6:Array = null;
            var _loc_7:int = 0;
            var _loc_8:SPlayerItemUpdate = null;
            var _loc_9:ItemData = null;
            var _loc_2:* = param1 as SLookupPlayerReply;
            if (this._playerModule && this._isLookUp)
            {
                this._isLookUp = false;
                LookupPlayerData.msg = _loc_2;
                this._playerModule.updateAttr(_loc_2.fightAttributeFinal, _loc_2.fightAttributeBase, _loc_2.miniPlayer.career);
                this._playerModule.updateHeadInfo(_loc_2.miniPlayer.name, _loc_2.miniPlayer.career, _loc_2.miniPlayer.level, _loc_2.miniPlayer.camp, _loc_2.honour, _loc_2.guildName);
                this._playerModule.setLifeValue(_loc_2.fightAttributeFinal.maxLife, _loc_2.life);
                this._playerModule.setMagicValue(_loc_2.fightAttributeFinal.maxMana, _loc_2.mana);
                _loc_3 = ExperienceConfig.instance.getValueByLevel(_loc_2.miniPlayer.level);
                this._playerModule.setExperienceValue(_loc_3, _loc_2.experience);
                _loc_4 = _loc_2.playerItemUpdates;
                _loc_5 = _loc_4.length;
                _loc_6 = [];
                _loc_7 = 0;
                _loc_7 = 0;
                while (_loc_7 < 15)
                {
                    
                    _loc_6.push(null);
                    _loc_7++;
                }
                _loc_7 = 0;
                while (_loc_7 < _loc_5)
                {
                    
                    _loc_8 = _loc_4[_loc_7] as SPlayerItemUpdate;
                    if (_loc_8.playerItem)
                    {
                        _loc_9 = new ItemData(_loc_8.playerItem);
                        _loc_6[(_loc_8.posIndex - 1)] = _loc_9;
                    }
                    _loc_7++;
                }
                this._playerModule.setEquipments(_loc_6, cache.role.entityInfo.career);
                this._playerModule.updateRoleModel(_loc_2.miniPlayer.sex);
                this._playerModule.vipInfoUpdate(_loc_2.miniPlayer.VIP);
                this._playerModule.setAcupointInfo();
                if (view.isHide)
                {
                    view.show();
                }
            }
            
        }

        private function viewHandler(event:DataEvent) : void
        {
            this.initView();
            var _loc_2:* = event.data as SEntityId;
            if (_loc_2.id == cache.role.entityInfo.entityId.id)
            {
            }
            else
            {
                this._isLookUp = true;
                GameProxy.playerInfoProxy.lookupRequest_async(cache.role.entityInfo.entityId, _loc_2);
            }
            
        }

    }
}
